package com.lzm.controller;


import com.github.pagehelper.PageInfo;
import com.lzm.pojo.Chargeproject;
import com.lzm.pojo.Drug;
import com.lzm.pojo.Menu;
import com.lzm.service.chargeProjectService;
import com.lzm.vo.ResultVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@ResponseBody
@RequestMapping("chargeProject")
@Controller
public class chargeProjectController {

    @Resource
    private chargeProjectService chargeProjectService;

    @RequestMapping(value = "list" ,method = RequestMethod.GET)
    public ResultVo<Chargeproject> getList(Integer pageNum,Integer pageSize,String chaP_name){
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize <= 0) {
            pageSize = 5;
        }
        PageInfo<Chargeproject> chargeprojectPageInfo = chargeProjectService.queryByPage(pageNum, pageSize, chaP_name);
        return new ResultVo(chargeprojectPageInfo);
    }
    @RequestMapping(value = "",method = RequestMethod.POST)
    public ResultVo<Chargeproject> queryById(Chargeproject chargeproject){
        int i = chargeProjectService.add(chargeproject);
        if(i==1) {
            return new ResultVo<>(chargeproject);
        }else {
            return new ResultVo<>(500,"内部错误");
        }
    }
    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public ResultVo<Chargeproject> queryById(@PathVariable("id") Integer chaP_id){
        Chargeproject chargeproject = chargeProjectService.queryById(chaP_id);
        return new ResultVo<>(chargeproject);
    }

    @RequestMapping(value = "{id}",method = RequestMethod.PUT)
    public ResultVo<Chargeproject> update(@PathVariable("id") Integer chaP_id,Chargeproject chargeproject){
        chargeproject.setChaP_id(chaP_id);
        int i = chargeProjectService.updateChargeProject(chargeproject);
        if(i==1){
            return new ResultVo<>(chargeproject);
        }
        return new ResultVo<>(500,"更新失败！服务器内部异常，请稍后再试");
    }
    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    public ResultVo<Chargeproject> delete(@PathVariable("id") Integer chaP_id){
        int i = chargeProjectService.delete(chaP_id);
        if(i==1){
            return new ResultVo<Chargeproject>();
        }
        return new ResultVo<>(500,"更新失败！服务器内部异常，请稍后再试");
    }
}
